﻿using B.X.Rabbit.ErrorCode;
using B.X.Rabbit.Read.Api.Application.Command.Login;
using B.X.Rabbit.Read.Api.Application.Command.Query;
using B.X.Rabbit.Read.Api.DTO;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.X.Rabbit.Read.Api.Controllers
{
    /// <summary>
    /// 
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ManagementController : ControllerBase
    {
        /// <summary>
        /// 中介者
        /// </summary>
        private readonly IMediator mediator;
        /// <summary>
        /// 日志
        /// </summary>
        private readonly ILogger<ManagementController> logger;
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="mediator">中介者</param>
        /// <param name="logger">日志</param>
        public ManagementController(IMediator mediator, ILogger<ManagementController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<UserDto>> UserLogin([FromQuery] LoginQueryCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="request"></param>
        /// <returns>返回任务</returns>
        [HttpGet]
        public async Task<ApiResult<ApiPaging<QueryDto>>> GetMyForm([FromQuery] QueryCommand request)
        {
            return await mediator.Send(request);
        }



    }

}
